//////////////////////////////////////////////////////////////////
// MattiseOS Kernel
// Date: 2008
// Author: Matthew Iselin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////

// Includes
#include <mattise.h>
#include <stdint.h>
#include <mem/util.h>
#include <mem/heap.h>
#include <kernio/io.h>

/**
	USE THESE when working with functions that will allocate memory
	to allow memory leak detection (they should go before and after
	the function call.
**/

// starts detection for memory leaks
uint32_t start_memleak_possible_block()
{
	// allocate a byte
	return (uint32_t) malloc( 1 );
}

// ends detection for memory leaks
void end_memleak_possible_block( uint32_t b )
{
	// free the block and allocate another byte
	free( (void*) b );
	uint32_t a = (uint32_t) malloc( 1 );

	// verify them
	if( b != a )
		printf( "Memory leak detected (%d bytes unfreed)!\n", a - b );
	else
		printf( "No memory leak detected\n" );
}
